package logic

import (
	"apple/applerpc/applerpc"
	"apple/applerpc/internal/svc"
	"apple/models/mysql"
	"context"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddLogic {
	return &AddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 添加
func (l *AddLogic) Add(in *applerpc.AddRequest) (*applerpc.AddResponse, error) {
	// todo: add your logic here and delete this line
	activity := mysql.Activity{
		Image:     in.Image,
		Name:      in.Name,
		Publisher: in.Publisher,
		Class:     in.Class,
		Message:   in.Message,
		UserId:    in.UserId,
	}
	mysql.DB.Debug().Create(&activity)
	return &applerpc.AddResponse{
		Id: int64(activity.ID),
	}, nil
}
